package com.example.bijiabao.controller;

import com.example.bijiabao.services.CollectionServices;
import com.example.bijiabao.entity.collect;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.bijiabao.entity.collectView;
import org.springframework.web.bind.annotation.*;
import com.example.bijiabao.utils.Result;

import java.util.List;

@RestController
@RequestMapping("like")
public class CollectionController {
    @Autowired
    private CollectionServices collectionServices;

    //添加收藏
    @PostMapping("/add")
    public Result insertcollection(@RequestBody collect collect){
        Result result = new Result();
        int i = collectionServices.insertcollect(collect);
        if (i==1){
            result.setCode(200);
            result.setMessage("添加成功");
        }else {
            result.setCode(400);
            result.setMessage("添加失败");
        }
        return result;
    }

    //删除收藏信息
    @GetMapping("/del")
    public Result deletedByID(Integer collectId) {
        Result result = new Result();
        int i = collectionServices.DelLikeByID(collectId);
        if (i == 1) {
            result.setCode(200);
            result.setMessage("删除成功");
        } else {
            result.setCode(400);
            result.setMessage("删除失败");
        }
        return result;
    }
        //查询用户自己的收藏
        @GetMapping("/find")
        public Result SelectLikeByUserID(@RequestParam("userId") Integer userId){
            Result result = new Result();
            List<collectView> lists = null;
            lists = collectionServices.SelectLikeByUserID(userId);
            result.setCode(200);
            result.setMessage("查询收藏成功");
            result.setObject(lists);
            return result;
        }
    }

